<?php

namespace App\Containers\AppSection\Log\Tasks;

use App\Containers\AppSection\Log\Data\Repositories\LogRepository;
use App\Ship\Exceptions\CreateResourceFailedException;
use App\Ship\Parents\Tasks\Task;
use Exception;

class CreateLogTask extends Task
{
    protected LogRepository $repository;

    public function __construct(LogRepository $repository)
    {
        $this->repository = $repository;
    }

    public function run(int $profileId, string $log, string $type = null, int $relation = null)
    {
        try {
            return $this->repository->create([
                'type_key' => $type,
                'profile_id' => $profileId,
                'log' => $log,
                'relation_id' => $relation
            ]);
        } catch (Exception $exception) {
            throw new CreateResourceFailedException();
        }
    }
}
